package com.yyairmarkyy.arctool.customview;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Point;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;

import com.yyairmarkyy.arctool.util.Utils;


/**
 * Created by yyairmarkyy on 2017/10/18.
 */

public class CenterView extends View{

    private Context context;
    private Paint paint;
    private int bgColor;
    private Bitmap bgIcon;
    private int iconSize;
    private Point iconPosition;

    public CenterView(Context context) {
        super(context);
        this.context = context;
        paint = new Paint();
        paint.setAntiAlias(true);
        paint.setDither(true);
        paint.setStyle(Paint.Style.FILL);

    }

    public CenterView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        this.context = context;

    }


    public void setBgColor(int color){
        this.bgColor = color;
        paint.setColor(bgColor);
    }

    public void setIcon(int resid,int size,Point iconPosition){
        bgIcon =  Utils.zoomImg(BitmapFactory.decodeResource(context.getResources(),resid),size,size);
        this.iconPosition = iconPosition;
    }

    public void setIconSize(int iconSize) {
        this.iconSize = iconSize;
    }


    @Override
    protected void onDraw(Canvas canvas) {
        canvas.drawCircle(getWidth(),getHeight(),getHeight(),paint);
        if (bgIcon != null && iconPosition != null)
            canvas.drawBitmap(bgIcon, iconPosition.x, iconPosition.y,null);

    }

}
